<!DOCTYPE html>
<html lang="en">

<head>

    <include file="Public/header" />
	
	<style>
	th{
		text-align:center;
	}
	
	.error {
	color:red
}
.parsley-error {
	border-color:#f32f53
}
.parsley-errors-list {
	display:none;
	margin:0;
	padding:0
}
.parsley-errors-list.filled {
	display:block
}
.parsley-errors-list>li {
	font-size:12px;
	list-style:none;
	color:#f32f53;
	margin-top:5px
}
	</style>
</head>

<body>

    <div id="wrapper">

        <include file="Public/nav" />

        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">分组授权</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>

            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                        	{$group.title} - 分组授权
                        </div>
                        
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                        	<div class="row">
                            	<form id="add_form" role="form">
                            		<input  name="group_id" value="{$group.id}" type="hidden"/>
                            		<div class="col-lg-12">
                            			<volist name="authRuleList" id="vo">
		                            		<div class="form-group">
		                                         <label>{$vo.title}</label> <br/>
		                                         <volist name="vo.child" id="v">
			                                         <label class="checkbox-inline">
		                                                <input 
		                                                <if condition="$v.flag eq 1">checked="checked"</if>
		                                                 value="{$v.id}" name="rule_id" type="checkbox">{$v.title}&nbsp;
		                                             </label>
	                                             </volist>
		                                     </div>
	                                     </volist>

	                                     <div class="form-group">
	                                     	<button type="submit" class="btn btn-default">提 交</button>
	                                     	<button type="reset" class="btn btn-default">重 置</button>
	                                     </div>
	                                     
                                     </div>
                            	</form>
                        	</div>

                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-6 -->
                <!-- /.col-lg-6 -->
            </div>
            
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <include file="Public/footer" />
	<script type="text/javascript" src="__RAC__/js/parsleyjs/parsley.min.js"></script>
	
	<script type="text/javascript">
	$(function () {
		$('#add_form').parsley().on('form:submit', function() {
			
			var group_id = $('input[name=group_id]').val();
			
			var rules = [];
			$('input:checkbox[name=rule_id]:checked').each(function(k){
				rules.push($(this).val());
			})

        	var layer_index = null;
           	$.ajax({
           	    type: "POST",
           	    url: "{:U('Group/rules_form')}",
           	    data: {
           	    	group_id : group_id,
           	    	rules : rules.join(',')
           	    },// 要提交的表单
           	    dataType: 'json',
           	    beforeSend: function(){
   					layer_index = layer.load(1, {
   					  	shade: [0.1, '#ccc'] //0.1透明度的白色背景
   					});
   				},
           	    success: function (data, response) {
           	    	layer.close(layer_index);
           	    	layer.msg('授权成功');
           	    },
           	    error: function (error) {
           	    	layer.close(layer_index);
           	    	layer.msg('error');
           	    }
           	  });
        	  
        	 return false;
        });
		
	});
	
	</script>
</body>

</html>
